/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main.models;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.NoneScoped;
import main.DBmodels.User;
import main.util.DAO;

/**
 *
 * @author Ariman
 */
@ManagedBean
@NoneScoped
public class Login {

    private String loginName = "";
    private String loginPass = "";
    private int find = 0;

    public Login() {
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getLoginPass() {
        return loginPass;
    }

    public void setLoginPass(String loginPass) {
        this.loginPass = loginPass;
    }

    public int getFind() {
        return find;
    }

    public void setFind(int find) {
        this.find = find;
    }

    public User logining() throws Exception {

        DAO dao = new DAO();
        User person = null;
        try {
            person = dao.validateUser(loginName, loginPass);
            if (person == null) {
                throw new Exception();
            }
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }
        loginName="";
        loginPass="";
        person.setPassword("");
        return person;
    }

    public String registration() {
        return "registration";
    }
}
